package com.ylfstu.Homework.homework13;

public class Homework13 {
    public static void main(String[] args) {
        Student student1 = new Student("joy", '男', 23, "00023102");
        student1.printMessage();

        Teacher teacher1 = new Teacher("mary", '女', 26, 3);
        teacher1.printMessage();

        Person[] persons = new Person[4];
        persons[0] = new Student("Nancy", '女', 21, "00033101");
        persons[1] = new Student("tom", '男', 22, "00014407");
        persons[2] = new Teacher("jack", '男', 30, 8);
        persons[3] = new Teacher("mary", '女', 27, 5);

        System.out.println("--------未排序前--------");
        for (int i = 0; i < persons.length; i++) {
            persons[i].printMessage();
        }

        Person temp ;
        for (int i = 0; i < persons.length - 1; i++) {
            for (int j = 0; j < persons.length - 1 - i; j++) {
                if (persons[j].getAge() < persons[j + 1].getAge()){
                    temp = persons[j];
                    persons[j] = persons[j + 1];
                    persons[j + 1] = temp;
                }
            }
        }

        System.out.println("--------排序后--------");
        for (int i = 0; i < persons.length; i++) {
            persons[i].printMessage();
        }

        Person p1 = new Student("Helen", '女', 24, "00023456");
        Person p2 = new Teacher("cahty", '女', 25, 4);
        Homework13 homework13 = new Homework13();
        homework13.test(p1);
        homework13.test(p2);
    }

    public void test(Person p){
        if (p instanceof Student){
            ((Student) p).study();
        } else if (p instanceof Teacher){
            ((Teacher) p).teach();
        } else {

        }
    }
}
